#ifndef LINEEDIT_H
#define LINEEDIT_H

#include "element.h"
#include <QVector>

class QLUISHARED_EXPORT LineEdit : public Element
{
    Q_OBJECT
public:
    LineEdit(Element *parent=NULL);

    /*********************************************************************
     *                    Copying
     * *******************************************************************/
public:
    virtual bool copyFrom(const Element *e) override;
    virtual Element* clone() const override;


    /*********************************************************************
     *                    Content
     * *******************************************************************/
public:
    Q_PROPERTY(QString text READ text WRITE setText)
    Q_PROPERTY(int backspaceKey READ backspaceKey WRITE setBackspaceKey)
    Q_PROPERTY(QList<int> alphaKeys READ alphaKeys WRITE setAlphaKeys)
    Q_PROPERTY(QList<int> numberKeys READ numberKeys WRITE setNumberKeys)

    void setText(const QString& text);
    QString text() const;

    void setBackspaceKey(int key);
    int backspaceKey() const;

    /**
     * @brief setAlphaAKey
     * @param key
     *
     * @note assume alpha is continuity after 'a'
     * @warning just bind once
     */
    void setAlphaKeys(QList<int> keys);
    QList<int> alphaKeys() const;

    /**
     * @brief setNumber0Key
     * @param key
     *
     * @note assume alpha is continuity after '0'
     * @warning just bind once
     */
    void setNumberKeys(QList<int> keys);
    QList<int> numberKeys() const;

protected:
    inline bool isAlphaKey(int key) const { return alphaKeys().contains(key); }
    inline bool isNumberKey(int key) const { return numberKeys().contains(key); }
    inline bool isBackspaceKey(int key) const { return key==backspaceKey(); }

private:
    QString text_;
    int backspace_key_;
    QList<int> alpha_keys_;
    QList<int> number_keys_;

    /*********************************************************************
     *                    Position & Size
     * *******************************************************************/
public:
    virtual QRect sizeHint() const;


    /*********************************************************************
     *                    paint
     * *******************************************************************/
protected:
    virtual void paintEvent() override;

    /*********************************************************************
     *                    event
     * *******************************************************************/
public slots:
    void onKeyEvent(int key, int value);

signals:
    void textChanged();

    /*********************************************************************
     *                    MetaInfo
     * *******************************************************************/
public:
    virtual QString getSignalSignature(const QString& name) const override;
};

#endif // LINEEDIT_H
